package just.stuff.morsels.ui.search;


import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.PropertyModel;

/**
 * Panel containing search form
 *
 */
public class SearchPanel extends Panel {

	private String query;
	
	public SearchPanel(String id) {
		super(id);
		Form<Void> f = new Form<Void>( "search" ) {
			public void onSubmit() {
				if( query != null && query.trim().length() != 0 ) {
					PageParameters pp = new PageParameters();
					pp.add( SearchResults.QUERY_PARAM, query );
					setResponsePage( SearchResults.class, pp );
				}
			}
		};
		f.add( new TextField<String>( "query", new PropertyModel<String>( this, "query")));
		
		add( f );
	}

}
